/**
 *
 * @author DorcasBless
 * you can find the Synaxarium at http://code.google.com/p/synaxarium/
 * April, 2009
 * Version 1.0.0
 *
 */

package com.christian;

import java.io.IOException;
import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;

public class SMSSender implements Runnable{
    private String destinationAddress;
    private String message;
    private SynMIDlet synMIDlet;
    public SMSSender(String destinationAddress, String message, SynMIDlet synMIDlet) {
        this.destinationAddress = destinationAddress;
        this.message = message;
        this.synMIDlet = synMIDlet;
    }
    public void run() {
        
        MessageConnection smsconn = null;
        
        try {
            /** Open the message connection. */
            smsconn = (MessageConnection)Connector.open(destinationAddress,Connector.WRITE);
            TextMessage txtmessage = (TextMessage)smsconn.newMessage(MessageConnection.TEXT_MESSAGE);
            txtmessage.setAddress(destinationAddress);
            txtmessage.setPayloadText(message);
            smsconn.send(txtmessage);
            synMIDlet.showAlertMessgeSent("\u062A\u0645 \u0627\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629 \u0628\u0646\u062C\u0627\u062D");
        } catch (Throwable t) {
            synMIDlet.showAlertMessgeSent(t.getMessage());
        }        
        if (smsconn != null) {
            try {
                smsconn.close();
            } catch (IOException ioe) {
                synMIDlet.showAlertMessgeSent(ioe.getMessage());
            }
        }
    }   
}